package com.example.itshome.network;

import android.app.Activity;
import android.widget.Toast;
import com.example.itshome.manager.UserInfoManager;
import com.example.itshome.util.ToastUtil;
import org.json.JSONException;
import org.json.JSONObject;

public class ClockInRequest extends AbstractNetworkRequest{

    private Runnable run;

    public ClockInRequest setRun(Runnable run) {
        this.run = run;
        return this;
    }

    public ClockInRequest(Activity activity) {
        super(activity);
    }

    @Override
    protected String getPathAndParams() {
        return "user/boot-sign-in?username="+ UserInfoManager.getInstance().getUser().getUsername();
    }

    @Override
    protected void handleResult(String result) {
        try {
            JSONObject jsonObject=new JSONObject(result);
            int code=jsonObject.getInt("code");
            if(code==104){
                setHandleResultRunnable(new Runnable() {
                    @Override
                    public void run() {
                        ToastUtil.showToast("今天已经签过到了",activity);
                    }
                });
            }
            else if(code==200){
                setHandleResultRunnable(new Runnable() {
                    @Override
                    public void run() {
                        run.run();
                    }
                });
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

}
